using System.Reflection;
using MediatR;
using Nest;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var url = builder.Configuration["ElasticSearch:Url"];
var defaultIndex = builder.Configuration["ElasticSearch:DefaultIndex"];
var settings = new ConnectionSettings(new Uri(url)).DefaultIndex(defaultIndex).BasicAuthentication(builder.Configuration["ElasticSearch:UserName"], builder.Configuration["ElasticSearch:PassWord"]);
var client = new ElasticClient(settings);
builder.Services.AddSingleton<IElasticClient>(client);
builder.Services.AddMediatR(Assembly.GetExecutingAssembly());
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();
